﻿using OrderSystem.Common;
using OrderSystem.DataAccess;
using OrderSystem.FormatOutput;
using OrderSystem.SystemFramework;
using OrderSystem.Templet;
using System;
using System.Collections;
using System.Data;
using System.Data.SqlClient;
using System.Drawing;
using System.IO;
using System.Windows.Forms;

namespace OrderSystem
{
    public partial class FormInvoiceSumUp : FormTemplet
    {
        private InvoiceCondition _invoiceCondition = null;

        private DataTable _dtSumUp = null;

        private FormNotifier f = null;

        private bool IsPressLeftButton = true;

        public FormInvoiceSumUp()
        {
            this.InitializeComponent();
        }

        public FormInvoiceSumUp(InvoiceCondition ic) : this()
        {
            this._invoiceCondition = ic;
            Invoices invoices = new Invoices();
            try
            {
                this._dtSumUp = invoices.GetSumUpByCondition(this._invoiceCondition);
            }
            catch (SqlException ex)
            {
                MessageBox.Show(ex.Message + "\r\n\r\n或者是连接数据库的通道出现故障，请检查！\r\n\r\n订单项信息可能没有读出来", "错误", MessageBoxButtons.OK, MessageBoxIcon.Hand);
            }
            catch (Exception ex2)
            {
                MessageBox.Show(ex2.Message + "\r\n\r\n订单信息可能没有读出来", "错误", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
            }
            invoices.Dispose();
            if (this._dtSumUp != null)
            {
                if (this._dtSumUp.Rows.Count > 0)
                {
                    this.dgSumUp.DataSource = null;
                    this.dgSumUp.DataSource = this._dtSumUp;
                }
                else
                {
                    MessageBox.Show("根据你提供的条件，在系统中没有找到你要得信息！\r\n\r\n信息可能没有读出来", "提示！", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                    this.dgSumUp.DataSource = null;
                    base.Dispose();
                }
            }
        }

        private void btnShow_Click(object sender, EventArgs e)
        {
            try
            {
                string text = this.dgSumUp.Rows[0].Cells[0].Value.ToString();
            }
            catch (Exception)
            {
                MessageBox.Show("表格中没有数据", "错误", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                return;
            }
            int rowIndex = this.dgSumUp.CurrentCell.RowIndex;
            new FormInvoiceInfo(this.dgSumUp.Rows[rowIndex].Cells[1].Value.ToString())
            {
                MdiParent = base.MdiParent
            }.Show();
        }

        private void dgSumUp_CellMouseDoubleClick(object sender, DataGridViewCellMouseEventArgs e)
        {
            if (e.RowIndex >= 0 && e.RowIndex <= this.dgSumUp.Rows.Count - 1)
            {
                new FormInvoiceInfo(this.dgSumUp.Rows[e.RowIndex].Cells[1].Value.ToString())
                {
                    MdiParent = base.MdiParent
                }.Show();
            }
        }

        private void btnCreateSumup_Click(object sender, EventArgs e)
        {
            this.saveFileDialog1.Filter = "Excel文件|*.xls";
            this.saveFileDialog1.Title = "请选择你要输入的路径和文件名";
            this.saveFileDialog1.OverwritePrompt = true;
            this.saveFileDialog1.RestoreDirectory = true;
            this.saveFileDialog1.FileName = "发货单总结.xls";
            string text = null;
            if (this.saveFileDialog1.ShowDialog() == DialogResult.OK)
            {
                text = this.saveFileDialog1.FileName;
                this.saveFileDialog1.Dispose();
                try
                {
                    File.Copy(Application.StartupPath + "\\model\\" + AppSettings.GetExcelSettings("invoiceSumup"), text, true);
                }
                catch (IOException ex)
                {
                    MessageBox.Show(ex.Message + "\r\n或者是: 和你要创建的相同文件名的目标文件正在使用，不能覆盖，请把它关闭或删除后在操作", "提示", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                    return;
                }
                catch (Exception ex2)
                {
                    MessageBox.Show(ex2.Message, "提示", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                    return;
                }
                try
                {
                    ExcelOperationInvoiceSumup excelOperationInvoiceSumup = new ExcelOperationInvoiceSumup(Application.StartupPath);
                    excelOperationInvoiceSumup.MakeSumupDataToExcel(text, this._dtSumUp);
                }
                catch (Exception ex2)
                {
                    MessageBox.Show(ex2.Message, "错误", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                }
            }
            else
            {
                this.saveFileDialog1.Dispose();
            }
        }

        private void btnShowTotal_Click(object sender, EventArgs e)
        {
            if (this._dtSumUp != null)
            {
                if (this._dtSumUp.Rows.Count < 1)
                {
                    MessageBox.Show("根据你的信息，在系统中没有找到你要得信息\r\n\r\n订单项信息可能没有读出来", "提示！", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                }
                else
                {
                    int num = 0;
                    decimal d = 0m;
                    decimal d2 = 0m;
                    decimal d3 = 0m;
                    for (int i = 0; i < this._dtSumUp.Rows.Count; i++)
                    {
                        num += Convert.ToInt32(this._dtSumUp.Rows[i]["数量"]);
                        d += Convert.ToDecimal(this._dtSumUp.Rows[i]["面积"]);
                        d2 += Convert.ToDecimal(this._dtSumUp.Rows[i]["金额"]);
                        if (Convert.ToBoolean(this._dtSumUp.Rows[i]["付款状态"]))
                        {
                            d3 += Convert.ToDecimal(this._dtSumUp.Rows[i]["金额"]);
                        }
                    }
                    this.txtResult.Text = string.Concat(new string[]
                    {
                        "总数量：",
                        num.ToString(),
                        "   总面积：",
                        d.ToString(),
                        LoginInfo.Role[PowerName.InvoiceData_SeePrice] ? ("   总金额：" + d2.ToString()) : "",
                        "   已付款：",
                        d3.ToString()
                    });
                }
            }
        }

        private void btnShowTypeSubtotal_Click(object sender, EventArgs e)
        {
            this.contextMenuStrip1.Show(this, new Point(this.btnShowTypeSubtotal.Left, this.btnShowTypeSubtotal.Bottom));
        }

        private void menuShowTypeSubtotal_1_Click(object sender, EventArgs e)
        {
            if (!LoginInfo.Role[PowerName.InvoiceData_SeePrice])
            {
                MessageBox.Show("你没有权限查看这里！", "提示！", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
            }
            else
            {
                Invoices invoices = new Invoices();
                DataSet dataSet = null;
                try
                {
                    dataSet = invoices.GetTypeSubtotalByCondition(this._invoiceCondition);
                }
                catch (SqlException ex)
                {
                    MessageBox.Show(ex.Message + "\r\n\r\n或者是连接数据库的通道出现故障，请检查！", "错误", MessageBoxButtons.OK, MessageBoxIcon.Hand);
                }
                catch (Exception ex2)
                {
                    MessageBox.Show(ex2.Message, "错误", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                }
                invoices.Dispose();
                if (dataSet != null)
                {
                    if (dataSet.Tables.Count == 2)
                    {
                        string text = "※ 发货单的分类信息如下：\r\n";
                        int num = 0;
                        decimal d = 0m;
                        decimal d2 = 0m;
                        decimal d3 = 0m;
                        string text2;
                        for (int i = 0; i < dataSet.Tables[0].Rows.Count; i++)
                        {
                            int num2 = Convert.ToInt32(dataSet.Tables[0].Rows[i][1]);
                            num += num2;
                            decimal num3 = Convert.ToDecimal(dataSet.Tables[0].Rows[i][2]);
                            d += num3;
                            decimal d4 = Convert.ToDecimal(dataSet.Tables[0].Rows[i][3]);
                            d2 += d4;
                            decimal d5 = Convert.ToDecimal(dataSet.Tables[0].Rows[i][4]);
                            decimal d6 = Convert.ToDecimal((num3 * d5).ToString("F4"));
                            d3 += d6;
                            text2 = text;
                            text = string.Concat(new string[]
                            {
                                text2,
                                "\r\n",
                                (i + 1).ToString().PadRight(3, ' '),
                                "、类型：",
                                CommonMethod.PadSpaceOnRight(dataSet.Tables[0].Rows[i][0].ToString(), 26),
                                "数量：",
                                CommonMethod.PadSpaceOnRight(dataSet.Tables[0].Rows[i][1].ToString(), 10),
                                "面积：",
                                CommonMethod.PadSpaceOnRight(dataSet.Tables[0].Rows[i][2].ToString(), 16),
                                "周长：",
                                CommonMethod.PadSpaceOnRight(dataSet.Tables[0].Rows[i][3].ToString(), 16),
                                "价格：",
                                dataSet.Tables[0].Rows[i][4].ToString()
                            });
                        }
                        text2 = text;
                        text = string.Concat(new string[]
                        {
                            text2,
                            "\r\n\r\n     ★数量为：",
                            num.ToString(),
                            "；   总平方为：",
                            d.ToString(),
                            "；   总周长为：",
                            d2.ToString(),
                            "；   金额为：",
                            d3.ToString()
                        });
                        text += "\r\n\r\n※ 工艺分类信息如下：\r\n";
                        decimal d7 = 0m;
                        decimal num4 = 0m;
                        for (int i = 0; i < dataSet.Tables[1].Rows.Count; i++)
                        {
                            d7 += Convert.ToDecimal(dataSet.Tables[1].Rows[i][1]);
                            num4 = Convert.ToDecimal((num4 + Convert.ToDecimal(dataSet.Tables[1].Rows[i][1]) * Convert.ToDecimal(dataSet.Tables[1].Rows[i][2])).ToString("F4"));
                            text2 = text;
                            text = string.Concat(new string[]
                            {
                                text2,
                                "\r\n",
                                (i + 1).ToString().PadRight(3, ' '),
                                "、工艺：",
                                CommonMethod.PadSpaceOnRight(dataSet.Tables[1].Rows[i][0].ToString(), 16),
                                "数量：",
                                CommonMethod.PadSpaceOnRight(dataSet.Tables[1].Rows[i][1].ToString(), 16),
                                "价格：",
                                dataSet.Tables[1].Rows[i][2].ToString()
                            });
                        }
                        text2 = text;
                        text = string.Concat(new string[]
                        {
                            text2,
                            "\r\n\r\n     ★加工工艺的数量为：",
                            d7.ToString(),
                            "；   加工工艺的金额为：",
                            num4.ToString()
                        });
                        text = string.Concat(new string[]
                        {
                            "《发货单类型_价格总结》".PadLeft(60, ' '),
                            "\r\n\r\n",
                            text,
                            "\r\n\r\n※ 总金额为：",
                            (d3 + num4).ToString()
                        });
                        if (ContentBox.ShowBox("发货单类型_价格总结", text, "是否保存这些数据 ?") == DialogResult.Yes)
                        {
                            this.saveFileDialog1.Filter = "Excel文件|*.xls";
                            this.saveFileDialog1.Title = "请选择你要保存的路径和文件名";
                            this.saveFileDialog1.FileName = "发货单类型_价格总结.xls";
                            if (this.saveFileDialog1.ShowDialog() != DialogResult.OK)
                            {
                                this.saveFileDialog1.Dispose();
                                return;
                            }
                            string fileName = this.saveFileDialog1.FileName;
                            this.saveFileDialog1.Dispose();
                            try
                            {
                                ExcelOperationTypeSubtotal excelOperationTypeSubtotal = new ExcelOperationTypeSubtotal(Application.StartupPath);
                                excelOperationTypeSubtotal.MakeDataToExcel(fileName, dataSet);
                            }
                            catch (Exception ex2)
                            {
                                MessageBox.Show(ex2.Message, "错误", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                            }
                        }
                    }
                    else
                    {
                        MessageBox.Show("发货单可能没有数据信息！", "提示！", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                    }
                }
                if (dataSet != null)
                {
                    dataSet.Dispose();
                }
            }
        }

        private void menuShowTypeSubtotal_2_Click(object sender, EventArgs e)
        {
            Invoices invoices = new Invoices();
            DataSet dataSet = null;
            try
            {
                dataSet = invoices.GetTypeSubtotalByCondition_2(this._invoiceCondition);
            }
            catch (SqlException ex)
            {
                MessageBox.Show(ex.Message + "\r\n\r\n或者是连接数据库的通道出现故障，请检查！", "错误", MessageBoxButtons.OK, MessageBoxIcon.Hand);
            }
            catch (Exception ex2)
            {
                MessageBox.Show(ex2.Message, "错误", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
            }
            invoices.Dispose();
            if (dataSet != null)
            {
                if (dataSet.Tables.Count == 2)
                {
                    string text = "※ 发货单的分类信息如下：\r\n";
                    int num = 0;
                    decimal d = 0m;
                    decimal d2 = 0m;
                    string text2;
                    for (int i = 0; i < dataSet.Tables[0].Rows.Count; i++)
                    {
                        int num2 = Convert.ToInt32(dataSet.Tables[0].Rows[i][1]);
                        num += num2;
                        decimal d3 = Convert.ToDecimal(dataSet.Tables[0].Rows[i][2]);
                        d += d3;
                        decimal d4 = Convert.ToDecimal(dataSet.Tables[0].Rows[i][3]);
                        d2 += d4;
                        text2 = text;
                        text = string.Concat(new string[]
                        {
                            text2,
                            "\r\n",
                            (i + 1).ToString().PadRight(3, ' '),
                            "、类型：",
                            CommonMethod.PadSpaceOnRight(dataSet.Tables[0].Rows[i][0].ToString(), 16),
                            "数量：",
                            CommonMethod.PadSpaceOnRight(dataSet.Tables[0].Rows[i][1].ToString(), 16),
                            "面积：",
                            CommonMethod.PadSpaceOnRight(dataSet.Tables[0].Rows[i][2].ToString(), 16),
                            "周长：",
                            dataSet.Tables[0].Rows[i][3].ToString()
                        });
                    }
                    text2 = text;
                    text = string.Concat(new string[]
                    {
                        text2,
                        "\r\n\r\n     ★数量为：",
                        num.ToString(),
                        "；   总平方为：",
                        d.ToString(),
                        "；   总周长为：",
                        d2.ToString()
                    });
                    text += "\r\n\r\n※ 工艺分类信息如下：\r\n";
                    decimal d5 = 0m;
                    for (int i = 0; i < dataSet.Tables[1].Rows.Count; i++)
                    {
                        d5 += Convert.ToDecimal(dataSet.Tables[1].Rows[i][1]);
                        text2 = text;
                        text = string.Concat(new string[]
                        {
                            text2,
                            "\r\n",
                            (i + 1).ToString().PadRight(3, ' '),
                            "、工艺：",
                            CommonMethod.PadSpaceOnRight(dataSet.Tables[1].Rows[i][0].ToString(), 16),
                            "数量：",
                            Convert.ToDecimal(dataSet.Tables[1].Rows[i][1]).ToString()
                        });
                    }
                    text = text + "\r\n\r\n     ★加工工艺的数量为：" + d5.ToString();
                    text = "《发货单类型总结》".PadLeft(45, ' ') + "\r\n\r\n" + text;
                    if (ContentBox.ShowBox("发货单类型总结", text, "是否保存这些数据 ?") == DialogResult.Yes)
                    {
                        this.saveFileDialog1.Filter = "Excel文件|*.xls";
                        this.saveFileDialog1.Title = "请选择你要保存的路径和文件名";
                        this.saveFileDialog1.FileName = "发货单类型总结.xls";
                        if (this.saveFileDialog1.ShowDialog() != DialogResult.OK)
                        {
                            this.saveFileDialog1.Dispose();
                            return;
                        }
                        string fileName = this.saveFileDialog1.FileName;
                        this.saveFileDialog1.Dispose();
                        try
                        {
                            ExcelOperationTypeSubtotal excelOperationTypeSubtotal = new ExcelOperationTypeSubtotal(Application.StartupPath);
                            excelOperationTypeSubtotal.MakeDataToExcel(fileName, dataSet);
                        }
                        catch (Exception ex2)
                        {
                            MessageBox.Show(ex2.Message, "错误", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                        }
                    }
                }
                else
                {
                    MessageBox.Show("发货单中可能没有数据信息！", "提示！", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                }
            }
            if (dataSet != null)
            {
                dataSet.Dispose();
            }
        }

        private void menuShowTypeSubtotal_3_Click(object sender, EventArgs e)
        {
            Invoices invoices = new Invoices();
            DataSet dataSet = null;
            try
            {
                dataSet = invoices.GetTypeSubtotalByCondition_3(this._invoiceCondition);
            }
            catch (SqlException ex)
            {
                MessageBox.Show(ex.Message + "\r\n\r\n或者是连接数据库的通道出现故障，请检查！", "错误", MessageBoxButtons.OK, MessageBoxIcon.Hand);
            }
            catch (Exception ex2)
            {
                MessageBox.Show(ex2.Message, "错误", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
            }
            invoices.Dispose();
            if (dataSet != null)
            {
                if (dataSet.Tables.Count == 3)
                {
                    string text = "※ 分析客户发货单量类型总结：\r\n";
                    int num = 0;
                    decimal d = 0m;
                    decimal d2 = 0m;
                    string text3;
                    for (int i = 0; i < dataSet.Tables[0].Rows.Count; i++)
                    {
                        int num2 = Convert.ToInt32(dataSet.Tables[0].Rows[i]["数量"]);
                        num += num2;
                        decimal d3 = Convert.ToDecimal(dataSet.Tables[0].Rows[i]["面积"]);
                        d += d3;
                        decimal d4 = Convert.ToDecimal(dataSet.Tables[0].Rows[i]["金额"]);
                        d2 += d4;
                        string str = "0";
                        string str2 = "0";
                        string text2 = "0";
                        for (int j = 0; j < dataSet.Tables[2].Rows.Count; j++)
                        {
                            if (dataSet.Tables[0].Rows[i]["公司名称"].ToString() == dataSet.Tables[2].Rows[j]["公司名称"].ToString() && dataSet.Tables[0].Rows[i]["类型"].ToString() == dataSet.Tables[2].Rows[j]["类型"].ToString())
                            {
                                str = dataSet.Tables[2].Rows[j]["数量"].ToString();
                                str2 = dataSet.Tables[2].Rows[j]["面积"].ToString();
                                text2 = dataSet.Tables[2].Rows[j]["金额"].ToString();
                                break;
                            }
                        }
                        text3 = text;
                        text = string.Concat(new string[]
                        {
                            text3,
                            "\r\n",
                            (i + 1).ToString().PadRight(3, ' '),
                            "、客户：",
                            CommonMethod.PadSpaceOnRight(dataSet.Tables[0].Rows[i][0].ToString(), 16),
                            "类型：",
                            CommonMethod.PadSpaceOnRight(dataSet.Tables[0].Rows[i][1].ToString(), 16),
                            "数量：",
                            CommonMethod.PadSpaceOnRight(dataSet.Tables[0].Rows[i][2].ToString() + "(未付" + str + ")", 16),
                            "面积：",
                            CommonMethod.PadSpaceOnRight(dataSet.Tables[0].Rows[i][3].ToString() + "(未付" + str2 + ")", 32),
                            "金额：",
                            dataSet.Tables[0].Rows[i][4].ToString(),
                            "(未付",
                            text2,
                            ")"
                        });
                    }
                    text3 = text;
                    text = string.Concat(new string[]
                    {
                        text3,
                        "\r\n\r\n     ★数量为：",
                        num.ToString(),
                        "；   总平方为：",
                        d.ToString(),
                        "；   总金额为：",
                        d2.ToString()
                    });
                    text += "\r\n\r\n※ 工艺分类信息如下：\r\n";
                    decimal d5 = 0m;
                    for (int i = 0; i < dataSet.Tables[1].Rows.Count; i++)
                    {
                        d5 += Convert.ToDecimal(dataSet.Tables[1].Rows[i][2]);
                        text3 = text;
                        text = string.Concat(new string[]
                        {
                            text3,
                            "\r\n",
                            (i + 1).ToString().PadRight(3, ' '),
                            "、客户：",
                            CommonMethod.PadSpaceOnRight(dataSet.Tables[1].Rows[i][0].ToString(), 16),
                            "工艺：",
                            CommonMethod.PadSpaceOnRight(dataSet.Tables[1].Rows[i][1].ToString(), 16),
                            "数量：",
                            Convert.ToDecimal(dataSet.Tables[1].Rows[i][2]).ToString()
                        });
                    }
                    text = text + "\r\n\r\n     ★加工工艺的数量为：" + d5.ToString();
                    text = "《客户发货单量类型总结》".PadLeft(45, ' ') + "\r\n\r\n" + text;
                    if (ContentBox.ShowBox("客户发货单量类型总结", text, "是否保存这些数据 ?") == DialogResult.Yes)
                    {
                        this.saveFileDialog1.Filter = "Excel文件|*.xls";
                        this.saveFileDialog1.Title = "请选择你要保存的路径和文件名";
                        this.saveFileDialog1.FileName = "客户发货单量类型总结.xls";
                        if (this.saveFileDialog1.ShowDialog() != DialogResult.OK)
                        {
                            this.saveFileDialog1.Dispose();
                            return;
                        }
                        string fileName = this.saveFileDialog1.FileName;
                        this.saveFileDialog1.Dispose();
                        try
                        {
                            ExcelOperationTypeSubtotal excelOperationTypeSubtotal = new ExcelOperationTypeSubtotal(Application.StartupPath);
                            excelOperationTypeSubtotal.MakeDataToExcel(fileName, dataSet);
                        }
                        catch (Exception ex2)
                        {
                            MessageBox.Show(ex2.Message, "错误", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                        }
                    }
                }
                else
                {
                    MessageBox.Show("发货单中可能没有数据信息！", "提示！", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                }
            }
            if (dataSet != null)
            {
                dataSet.Dispose();
            }
        }

        private void menuShowTypeSubtotal_4_Click(object sender, EventArgs e)
        {
            if (!LoginInfo.Role[PowerName.InvoiceData_SeePrice])
            {
                MessageBox.Show("你没有权限查看这里！", "提示！", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
            }
            else
            {
                Invoices invoices = new Invoices();
                DataTable dataTable = null;
                try
                {
                    dataTable = invoices.GetTypeSubtotalByCondition_4(this._invoiceCondition);
                }
                catch (SqlException ex)
                {
                    MessageBox.Show(ex.Message + "\r\n\r\n或者是连接数据库的通道出现故障，请检查！", "错误", MessageBoxButtons.OK, MessageBoxIcon.Hand);
                }
                catch (Exception ex2)
                {
                    MessageBox.Show(ex2.Message, "错误", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                }
                invoices.Dispose();
                if (dataTable != null)
                {
                    if (dataTable.Rows.Count > 0)
                    {
                        string text = "※ 分析客户发货单金额：\r\n";
                        decimal d = 0m;
                        for (int i = 0; i < dataTable.Rows.Count; i++)
                        {
                            decimal d2 = Convert.ToDecimal(dataTable.Rows[i][1]);
                            d += d2;
                            string text2 = text;
                            text = string.Concat(new string[]
                            {
                                text2,
                                "\r\n",
                                (i + 1).ToString().PadRight(3, ' '),
                                "、客户：",
                                CommonMethod.PadSpaceOnRight(dataTable.Rows[i][0].ToString(), 16),
                                "金额：",
                                dataTable.Rows[i][1].ToString()
                            });
                        }
                        text = text + "\r\n\r\n     ★总金额为：" + d.ToString();
                        text = "《分析客户发货单金额》".PadLeft(45, ' ') + "\r\n\r\n" + text;
                        if (ContentBox.ShowBox("分析客户发货单金额", text, "是否保存这些数据 ?") == DialogResult.Yes)
                        {
                            this.saveFileDialog1.Filter = "Text文件|*.txt";
                            this.saveFileDialog1.Title = "请选择你要保存的路径和文件名";
                            this.saveFileDialog1.FileName = "分析客户发货单金额.txt";
                            if (this.saveFileDialog1.ShowDialog() == DialogResult.OK)
                            {
                                string fileName = this.saveFileDialog1.FileName;
                                this.saveFileDialog1.Dispose();
                                try
                                {
                                    OrderSystem.SystemFramework.TextWriter.WriteText(fileName, text);
                                }
                                catch (Exception ex2)
                                {
                                    MessageBox.Show(ex2.Message, "提示", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                                }
                            }
                            else
                            {
                                this.saveFileDialog1.Dispose();
                            }
                        }
                    }
                    else
                    {
                        MessageBox.Show("订单中可能没有数据信息！", "提示！", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                    }
                }
                if (dataTable != null)
                {
                    dataTable.Dispose();
                }
            }
        }

        private void FormOrderList_Load(object sender, EventArgs e)
        {
            if (!LoginInfo.Role[PowerName.InvoiceData_SeePrice])
            {
                if (this.dgSumUp != null)
                {
                    this.dgSumUp.Columns["金额"].Visible = false;
                }
            }
            this.dgSumUp.AutoResizeColumns();
        }

        private void btnClose_Click(object sender, EventArgs e)
        {
            base.Close();
        }

        private void btnDelete_Click(object sender, EventArgs e)
        {
            if (MessageBox.Show("确定删除数据吗？", "提示", MessageBoxButtons.OKCancel, MessageBoxIcon.Question) != DialogResult.Cancel)
            {
                if (this.dgSumUp.Rows.Count < 1)
                {
                    MessageBox.Show("没有数据！", "提示", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                }
                else
                {
                    Invoices invoices = new Invoices();
                    bool flag = false;
                    try
                    {
                        flag = invoices.Delete(Convert.ToInt64(this.dgSumUp.Rows[this.dgSumUp.CurrentRow.Index].Cells[0].Value));
                    }
                    catch (SqlException ex)
                    {
                        MessageBox.Show(ex.Message + "\r\n\r\n或者是连接数据库的通道出现故障，请检查！", "提示", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                    }
                    catch (Exception ex2)
                    {
                        MessageBox.Show(ex2.Message, "提示", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                    }
                    invoices.Dispose();
                    if (flag)
                    {
                        MessageBox.Show("操作成功！", "成功", MessageBoxButtons.OK, MessageBoxIcon.Asterisk);
                        this.dgSumUp.Rows.Remove(this.dgSumUp.CurrentRow);
                        this._dtSumUp.AcceptChanges();
                    }
                }
            }
        }

        private void dgSumUp_CellClick(object sender, DataGridViewCellEventArgs e)
        {
            if (e.ColumnIndex == 8)
            {
                if (!LoginInfo.Role[PowerName.Order_Payed])
                {
                    MessageBox.Show("你没有操作这里的权限！", "系统提示", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                }
                else
                {
                    string text = this.dtpPayDate.Value.ToShortDateString();
                    Invoices invoices = new Invoices();
                    bool flag = false;
                    try
                    {
                        flag = invoices.PayForInvoice(this.dgSumUp.Rows[e.RowIndex].Cells[1].Value.ToString(), !(bool)this.dgSumUp.Rows[e.RowIndex].Cells[e.ColumnIndex].Value, text);
                    }
                    catch (SqlException ex)
                    {
                        MessageBox.Show(ex.Message + "\r\n\r\n数据库出现了错误", "错误", MessageBoxButtons.OK, MessageBoxIcon.Hand);
                    }
                    catch (Exception ex2)
                    {
                        MessageBox.Show(ex2.Message, "错误", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                    }
                    invoices.Dispose();
                    if (flag)
                    {
                        if ((bool)this.dgSumUp.Rows[e.RowIndex].Cells[e.ColumnIndex].Value)
                        {
                            this.dgSumUp.Rows[e.RowIndex].Cells[e.ColumnIndex].Value = false;
                            this.dgSumUp.Rows[e.RowIndex].Cells[e.ColumnIndex + 1].Value = DBNull.Value;
                        }
                        else
                        {
                            this.dgSumUp.Rows[e.RowIndex].Cells[e.ColumnIndex].Value = true;
                            this.dgSumUp.Rows[e.RowIndex].Cells[e.ColumnIndex + 1].Value = text;
                        }
                    }
                }
            }
        }

        private void btnPayed_Click(object sender, EventArgs e)
        {
            if (!LoginInfo.Role[PowerName.Order_Payed])
            {
                MessageBox.Show("你没有操作这里的权限！", "系统提示", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
            }
            else if (this.dgSumUp.SelectedRows.Count < 1)
            {
                MessageBox.Show("没有选择任何行！", "提示", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
            }
            else
            {
                Invoices invoices = new Invoices();
                bool flag = false;
                try
                {
                    ArrayList arrayList = new ArrayList();
                    for (int i = 0; i < this._dtSumUp.Rows.Count; i++)
                    {
                        if (this.dgSumUp.Rows[i].Selected)
                        {
                            arrayList.Add(this.dgSumUp.Rows[i].Cells[1].Value.ToString());
                        }
                    }
                    string text = this.dtpPayDate.Value.ToShortDateString();
                    for (int i = 0; i < arrayList.Count; i++)
                    {
                        flag = false;
                        flag = invoices.PayForInvoice(arrayList[i].ToString(), true, text);
                        for (int j = 0; j < this._dtSumUp.Rows.Count; j++)
                        {
                            if (this._dtSumUp.Rows[j][1].ToString() == arrayList[i].ToString())
                            {
                                DataRow dataRow = this._dtSumUp.Rows[j];
                                dataRow["付款状态"] = true;
                                dataRow["付款时间"] = text;
                                dataRow.AcceptChanges();
                                break;
                            }
                        }
                    }
                }
                catch (SqlException ex)
                {
                    MessageBox.Show(ex.Message, "提示", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                }
                catch (Exception ex2)
                {
                    MessageBox.Show(ex2.Message, "提示", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                }
                invoices.Dispose();
                if (flag)
                {
                    MessageBox.Show("设置成功", "Success", MessageBoxButtons.OK, MessageBoxIcon.Asterisk);
                }
            }
        }

        private void dgSumUp_MouseDown(object sender, MouseEventArgs e)
        {
            if (e.Button == MouseButtons.Left)
            {
            }
            if (this.f != null && this.f.Visible)
            {
                this.f.Hide();
            }
        }

        private void dgSumUp_MouseMove(object sender, MouseEventArgs e)
        {
            if (e.Button == MouseButtons.Left && this.dgSumUp.SelectedCells.Count > 1)
            {
                this.IsPressLeftButton = true;
                if (this.f == null)
                {
                    this.f = new FormNotifier();
                }
                this.f.Left = Control.MousePosition.X + 17;
                this.f.Top = Control.MousePosition.Y;
                if (!this.f.Visible)
                {
                    this.f.Show();
                }
            }
        }

        private void dgSumUp_MouseUp(object sender, MouseEventArgs e)
        {
        }

        private void dgSumUp_CellEnter(object sender, DataGridViewCellEventArgs e)
        {
            if (this.IsPressLeftButton)
            {
                int num = 0;
                decimal d = 0m;
                decimal d2 = 0m;
                for (int i = 0; i < this.dgSumUp.SelectedCells.Count; i++)
                {
                    if (this.dgSumUp.SelectedCells[i].OwningColumn.HeaderText == "数量")
                    {
                        num += Convert.ToInt32(this.dgSumUp.SelectedCells[i].Value);
                    }
                    else if (this.dgSumUp.SelectedCells[i].OwningColumn.HeaderText == "面积")
                    {
                        d += Convert.ToDecimal(this.dgSumUp.SelectedCells[i].Value);
                    }
                    else if (this.dgSumUp.SelectedCells[i].OwningColumn.HeaderText == "金额")
                    {
                        d2 += Convert.ToDecimal(this.dgSumUp.SelectedCells[i].Value);
                    }
                }
                if (this.f != null)
                {
                    this.f.lbl.Text = string.Concat(new string[]
                    {
                        "数量：",
                        num.ToString(),
                        "\r\n面积：",
                        d.ToString(),
                        "\r\n金额：",
                        d2.ToString()
                    });
                }
            }
        }
    }
}
